/**
 * Created by ghh on 2016/12/14.
 */
$(document).ready(function(){
    var timestamp = Math.round(new Date().getTime()/1000),
        forurl = window.location.href,
        sourceUrl = "http://res.cngoldres.com/libs/touchSlide/1.1/touchSlide.1.1.source.js";
    if(forurl.indexOf("/gold")>=0 || forurl.indexOf("/ag")>=0) {
        top_important();
        if(forurl.length<=25){
            bottom_important();
        }else{
            $.getScript(sourceUrl).done(function(){
                bottom_important();
            });
        }
    }else{
        if(forurl.indexOf("/futures/")>=0){
            top_important();
            if (timestamp>1482336000){
                $.getScript(sourceUrl).done(function(){
                    bottom_important();
                });//期货广告12月22日到期
            }else{
                $('.important_open').html('<dl class="important_open"><a href="http://www.hjtd88.com/mhd3/?cngold" rel="external nofollow" id="click_fpjt"><img src="https://res.cngoldres.com/mobile/images/important_information10.jpg" alt="免费领取688元" width="99.9%" style="height: 76.8px; width: 480px;"></a><dd class="important_close"><img src="https://res.cngoldres.com/mobile/images/m02_close.png" alt="关闭" width="29.9px" height="29.9px"></dd><img src="https://res.cngoldres.com/mobile/images/leftTip.png" alt="标识" width="29" height="16" style="position:absolute;left:0;bottom:0"></dl>');
            }
        }else{//判断条件排除测试广告位
            if(forurl.indexOf("gjhj.html")<0 && forurl.indexOf("gjhj_xhhj.html")<0){
                $.getScript(sourceUrl).done(function(){
                    bottom_important();
                });
                if (forurl.indexOf("dy313.html")<0 && forurl.indexOf("dy1531.html")<0 && forurl.indexOf("dy110.html")<0 && forurl.indexOf("dy157.html")<0 && forurl.indexOf("dy140.html")<0 && forurl.indexOf("dy106.html")<0 && forurl.indexOf("dy113.html")<0 && forurl.indexOf("dy328.html")<0) {
                    top_important();
                };
            }
        }
    };
    function top_important(){
        if (forurl.indexOf("insurance")<0) {
            $('.top-important').html('<a href="http://m.cngold.org/ag/zdy300.html"><img src="http://res.cngoldres.com/mobile/images/m5_top_important8.gif"></a><img src="https://res.cngoldres.com/mobile/images/leftTip.png" alt="标识" width="29" height="16" style="position:absolute;left:0;bottom:0">');
        };//保险头部广告单独投放
    };
    function bottom_important(){
        $('.important_open').attr('id','important');
        $('.important_open').html('<style>.important_open .hd,.important_open .tempWrap,.important_open .bd,.important_open a img{padding:0;margin:0;line-height:initial;vertical-align:initial;}.important_open .hd{ width:100%; position:absolute; z-index:1; bottom:0; text-align:center;}.important_open .hd ul{ overflow:hidden; display:-moz-box; display:-webkit-box; display:box; height:5px; background-color:rgba(51,51,51,0.5);  display:none; }.important_open .hd ul li{ -moz-box-flex:1; -webkit-box-flex:1; box-flex:1;}.important_open .hd ul .on{ background:#FF4000;}.important_open .bd{ background: #fff;position:relative; z-index:0;padding:0;margin:0}.important_open .bd li img,.important_open .bd li a img{ width:100%;height:auto;font-size: initial;}.important_open .bd li a{ -webkit-tap-highlight-color:rgba(0, 0, 0, 0);}</style><div class="hd"><ul></ul></div><div class="bd"><ul><li><a href="https://regist.fxbtg-bank.com/custom/qmUZne"><img src="https://res.cngoldres.com/mobile/images/important_information10.gif" /></a></li><li><a href="https://tg.cngold.org/m/hqcs/jyhln.html?=ad"><img src="http://res.cngoldres.com/mobile/images/t6_jinyinhln_tupian.gif" /></a></li></ul></div><dd class="important_close"><img src="https://res.cngoldres.com/mobile/images/m02_close.png" alt="关闭" width="29.9px" height="29.9px"></dd><img src="https://res.cngoldres.com/mobile/images/leftTip.png" alt="标识" width="29" height="16" style="position:absolute;left:0;bottom:0">');
        TouchSlide({
            slideCell:"#important",
            titCell:".hd ul",
            mainCell:".bd ul",
            effect:"leftLoop",
            autoPlay:true,
            autoPage:true
        });
        // var thisHeight = $('#important img:eq(0)').height();
        // $('#important img:eq(1)').height(thisHeight+'px');
        // 为了广告图片高度一致设置，但行情加了这个底部广告出现错乱，暂时注释掉
        $('.important_close').click(function(){
            $('.important_open').hide();
        });
    }
    //关闭广告
    $('.freeHotline-close').click(function(){
        $('.freeHotline-open').hide();
        $("footer").css("padding-bottom","10px");
    });
    $('.important_close').click(function(){
        $('.important_open').hide();
        $("footer").css("padding-bottom","10px");
    });
    //变换窗口尺寸
    var bodyWidth = $(document.body).width();
    var docWidth = $(document).width();
    $('#click_fpjt img').css({width:bodyWidth + 'px',height:bodyWidth*0.16 + 'px'});
    window.onresize = function(){
        bodyWidth = $(document.body).width();
        docWidth = $(document).width();
        if($(".important_open").width()!=0){
            $('.important_open').css({width:bodyWidth + 'px',height:bodyWidth*0.16 + 'px'});
            $('#click_fpjt img').css({width:bodyWidth + 'px',height:bodyWidth*0.16 + 'px'});
        };
        if($(".freeHotline-open").width()!=0){
            $('.freeHotline-open').css({width:bodyWidth + 'px',height:bodyWidth*0.16 + 'px'});
            $('#click_fpjt img').css({width:bodyWidth + 'px',height:bodyWidth*0.16 + 'px'});
        }
    }
});